package common

import (
	"context"
	"github.com/gin-gonic/gin"
	"log"
)

//获取RequestId
func Print_RequestId(c *gin.Context) string {
	var rid string

	if rid = c.Query("RequestId"); rid != "" {
		c.Set("RequestId", rid)
		log.Printf("RequestId:%+v", rid)
	}

	if rid_interface, ok := c.Get("RequestId"); ok {
		if v, bool := rid_interface.(string); bool {
			rid = v
		}
		log.Printf("RequestId:%+v", rid)
	}

	//给上下文赋值时：key必须是为可判断是否为空的类型，不能为内置的string类型或其他，可鼠标移至WithValue初查看注释
	type favContextKey string
	key := favContextKey("RequestId")
	if v := c.Value("RequestId"); v != nil {
		context.WithValue(c, key, rid)
	}

	return rid
}
